	<template>
	<div id="subhome" @scroll="scrollEvent">
        <v-nav :style="this.$route.path =='/home/index/00'?'':''"></v-nav>
        <div style="margin-top: .8rem">
            <!--<v-barrage></v-barrage>-->
            <router-view></router-view>
            <div style="width: 100%;position: relative;overflow: hidden;">
                <v-swiper :imgArrays="imgArrays"></v-swiper>
            </div>
            <v-funButton :funButton="funButton"></v-funButton>
            <div style="height: .2rem;background: #f6f6f6;"></div>
            <div class="banner" v-for="(v,k) in adGroup" :key="k">
                <img :src="v.img_url" :id="v.id" @click="goAnyWhere(v.aim,v.qrCode)">
            </div>
            <!--<v-TopGuess :hotArrays="hotArrays" :title_id="title_id" :title="title"></v-TopGuess>-->
            <div style="padding: 0.6rem 0 0.6rem 0;width: 100%; overflow: hidden;background: #fff">
                <div class="new">
                    <span>{{activityTil}}</span>
                </div>
                <v-swipers :imgArr="imgArr"></v-swipers>
            </div>
            <v-hotlist :proGroup="proGroup"></v-hotlist>
        </div>
	</div>
</template>

<script>
    import store from "../../store/newStore.js";
	import Nav from "../nav.vue";	
	import Swiper from "./newSwiper.vue";
	import SwiperTd from "./swiper3D.vue";
	import funButton from "./funButton.vue"
    import share from "../../share/share.js";
	import config from "../../config/config.js";
	import Hotlist from "./hotlist.vue";
	import TopGuess from "./topGuess.vue";

  /*  import Barrage from "../../barrage/barrage.vue";*/
    import MtaH5 from 'mta-h5-analysis';
	export default {
      store,
      components: {
        "v-swiper": Swiper,
        "v-swipers": SwiperTd,
        "v-nav": Nav,
        "v-funButton": funButton,
        "v-hotlist": Hotlist,
        "v-TopGuess": TopGuess,

        /*"v-barrage":Barrage*/
      },
      data() {
        return {
          imgArrays: [],
          hotArrays: [],
          activityTil: '',
          adGroup: [],
          funButton: [],
          imgArr: [],
          proGroup: [],
          pageSize: 1,
          my_scroller: '',
          newTop:''
        }
      },
      methods: {
        scrollEvent(e) {
          sessionStorage.setItem('top', e.target.scrollTop);
        },
        goOther(type, url) {
          if (type == 1) {
            this.$router.push(url);
          } else if (type == 2) {
            location.href = url;
          }
        },

        goSearch() {
          this.$router.push("/search");
        },
        goAnother(url) {
          this.$router.push(url);
        },

        getData(pageSize) {
          share({})
          var value = JSON.stringify({"page": pageSize, "id": "00", "token": localStorage.getItem('token')}),
            key = demo(value);
          axios.post('/Home/home/HomeIndex', {
            key: key,
            value: value
          }, config)
            .then(function (response) {
              if (response.data.code == 200) {
                if (response.data.data.proGroup.pageNum == pageSize) {
                  this.$nextTick(function () {
                    this.allLoaded = true;
                  })
                } else {
                  this.$nextTick(function () {
                    this.allLoaded = false;
                  })
                }
                if (pageSize == 1) {
                  //轮播图
                  this.imgArrays = response.data.data.imgArrays;
                  //活动标题
                  this.activityTil = response.data.data.recommodList.title;
                  //广告位
                  this.adGroup = response.data.data.adGroup;
                  //功能键
                  this.funButton = response.data.data.funButton;
                  //3d轮播
                  this.imgArr = response.data.data.recommodList.data;
                  //商品列表
                  this.proGroup = response.data.data.proGroup.data;
                  this.hotArrays = response.data.data.hotArrays.data;
                  this.title = response.data.data.hotArrays.title;
                  this.title_id = response.data.data.hotArrays.title_id;
                  this.$store.commit('increment', response.data.ticket);
                } else {
                }
              }

            }.bind(this))
            .catch(function (error) {
              console.log(error);
            });
        },
        goAnyWhere(url, qrCode) {
          this.$router.push({
            path: url,
            query: {
              qrCode: qrCode
            }
          })
        },
        setScroll: function () {
          // 定义一个保存坐标的方法
          var that=this;
          let oTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
          sessionStorage.setItem(this.$route.fullPath, 10)
        }
      },
      computed: {
        ticket() {
          return this.$store.state.getTicket;
        }
      },
      activated() {
        if (sessionStorage.getItem('top')) {
          this.$el.scrollTop = sessionStorage.getItem('top');
        }
        this.getData(this.pageSize);
        MtaH5.init({
          "sid": '500594815',
          "cid": '500595819',
          "autoReport": 0,
          "senseHash": 0,
          "senseQuery": 0,
          "performanceMonitor": 0,
          "ignoreParams": []
        });
        MtaH5.pgv();
        this.setScroll();
        let oHref = this.$route.fullPath;
        // 检查有没有坐标 如果有就跳转到
        // if (sessionStorage.getItem(oHref)) {
        //   let timer = setInterval(function () {
        //     let scrollData = sessionStorage.getItem(oHref)
        //     document.documentElement.scrollTop = scrollData;
        //     document.body.scrollTop = scrollData;
        //     clearInterval(timer);
        //     sessionStorage.removeItem('/home/index/00')
        //   }, 600)
        // }


      },
      deactivated () {
        // alert(document.getElementById('subhome').scrollTop + '*' + document.getElementById('home').scrollTop);
      },
      beforeDestroy:function () {
        // 页面销毁时清除坐标
        sessionStorage.removeItem('/home/index/00')
      }
    }
</script>

<style>
</style>